using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace MageDefender.GameObjects
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Scenery : Microsoft.Xna.Framework.DrawableGameComponent
    {
        GameClasses.GameModel sceneryModel;
        GameClasses.GameModel treesModel;
        GameClasses.GameModel riverModel;
        GameClasses.GameModel shroomsModel;

        public GameClasses.GameModel SceneryModel
        {
            get { return sceneryModel; }
            set { sceneryModel = value; }
        }

        public Scenery(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
            sceneryModel = new GameClasses.GameModel(game);
            treesModel = new GameClasses.GameModel(game);
            riverModel = new GameClasses.GameModel(game);
            shroomsModel = new GameClasses.GameModel(game);
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public void Initialize(Matrix projMatrix, Matrix viewMatrix)
        {
            // TODO: Add your initialization code here
            sceneryModel.Initialize("Models\\plane", "Models\\terrain_tex", "Textures\\Toon", projMatrix, viewMatrix);
            treesModel.Initialize("Models\\trees", "Models\\tree1_d", "Textures\\Toon", projMatrix, viewMatrix);
            riverModel.Initialize("Models\\planeRiver", "Textures\\water", "Textures\\Toon", projMatrix, viewMatrix);
            shroomsModel.Initialize("Models\\shrooms", "Models\\shroom_tex", "Textures\\Toon", projMatrix, viewMatrix);

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Update(GameTime gameTime, Vector3 vecEye, Matrix viewMatrix)
        {
            // TODO: Add your update code here
            Matrix objectMatrix = Matrix.CreateRotationX(0) * Matrix.CreateRotationY(0) * Matrix.CreateTranslation(0.0f,0.0f,0.0f);
            Matrix renderMatrix = Matrix.CreateScale(0.0080f);
            renderMatrix = objectMatrix * renderMatrix;
            sceneryModel.Update(vecEye, viewMatrix, renderMatrix, gameTime);
            riverModel.Update(vecEye, viewMatrix, renderMatrix, gameTime);

            objectMatrix = Matrix.CreateRotationX(0) * Matrix.CreateRotationY(0) * Matrix.CreateTranslation(0.0f, 50.0f, 0.0f);
            renderMatrix = Matrix.CreateScale(0.0080f);
            renderMatrix = objectMatrix * renderMatrix;
            treesModel.Update(vecEye, viewMatrix, renderMatrix, gameTime);
            shroomsModel.Update(vecEye, viewMatrix, renderMatrix, gameTime);

            base.Update(gameTime);
        }

        public void DrawWithGround(GameTime gameTime)
        {
            sceneryModel.Draw(gameTime);
            riverModel.Draw(gameTime);
            Draw(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            treesModel.Draw(gameTime);
            shroomsModel.Draw(gameTime);

            base.Draw(gameTime);
        }
    }
}